#include<iostream>
#include<iomanip>
using namespace std;
double a[100005],b[100005];
bool cmp(double x,double y){
    return x>y;
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
    }
    sort(a+1,a+1+n,cmp);
    sort(b+1,b+1+n,cmp);
    double ans=0;
    double ansa=0;
    double ansb=0;
    int r=1;
    for(int l=1;l<=n;l++){
        ansa+=a[l];
        ans=max(ans,min(ansa-l-r,ansb-l-r));
        while(ansb<ansa&&r<n){
            r++;
            ansb+=b[r];

             ans=max(ans,min(ansa-l-r,ansb-l-r));
        }
    }
    cout<<fixed<<setprecision(4)<<ans<<'\n';
    return 0;
}